home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / Manuels & Misc / Assembly / AOA.ZIP / CH13 / HEXDUMP.ASM < prev    next >
Encoding:
Assembly Source File  |  1996-02-24  |  2.7 KB  |  132 lines

  1.         include        stdlib.a
  2.         includelib    stdlib.lib
  3. cseg        segment        byte public 'CODE'
  4.         assume        cs:cseg, ds:dseg, es:dseg, ss:sseg
  5.  
  6. ; Note CR and LF are already defined in STDLIB.A
  7.  
  8. tab        equ    09h
  9.  
  10. MainPgm     proc    far
  11.  
  12. ; Properly set up the segment registers:
  13.  
  14.         mov    ax, seg dseg
  15.         mov    es, ax            ;Leave DS pointing at PSP
  16.  
  17. ;---------------------------------------------------------------
  18. ;
  19. ; First, parse the command line to get the filename:
  20.  
  21.         mov    si, 81h             ;Pointer to command line
  22.         lea    di, FileName        ;Pointer to FileName buffer
  23. SkipDelimiters:
  24.         lodsb                ;Get next character
  25.         call    TestDelimiter
  26.         je    SkipDelimiters
  27.  
  28. ; Assume that what follows is an actual filename
  29.  
  30.         dec    si            ;Point at 1st char of name
  31. GetFName:    lodsb
  32.         cmp    al, 0dh
  33.         je    GotName
  34.         call    TestDelimiter
  35.         je    GotName
  36.         stosb                ;Save character in file name
  37.         jmp    GetFName
  38.  
  39. ; We're at the end of the filename, so zero-terminate it as 
  40. ; required by DOS.
  41.  
  42. GotName:    mov    byte ptr es:[di], 0
  43.         mov    ax, es            ;Point DS at DSEG
  44.         mov    ds, ax
  45.  
  46. ; Now process the file
  47.  
  48.         mov    ah, 3dh
  49.         mov    al, 0            ;Open file for reading
  50.         lea    dx, Filename        ;File to open
  51.         int    21h
  52.         jnc    GoodOpen
  53.         print
  54.         byte    'Cannot open file, aborting program...',cr,0
  55.         jmp    PgmExit
  56.  
  57. GoodOpen:    mov    FileHandle, ax        ;Save file handle
  58.         mov    Position, 0        ;Initialize file position
  59. ReadFileLp:    mov    al, byte ptr Position
  60.         and    al, 0Fh             ;Compute (Position MOD 16)
  61.         jnz    NotNewLn        ;Every 16 bytes start a line
  62.         putcr
  63.         mov    ax, Position        ;Print offset into file
  64.         xchg    al, ah
  65.         puth
  66.         xchg    al, ah
  67.         puth
  68.         print
  69.         byte    ': ',0
  70.  
  71. NotNewLn:    inc    Position        ;Increment character count
  72.         mov    bx, FileHandle
  73.         mov    cx, 1            ;Read one byte
  74.         lea    dx, buffer        ;Place to store that byte
  75.         mov    ah, 3Fh             ;Read operation
  76.         int    21h
  77.         jc    BadRead
  78.         cmp    ax, 1            ;Reached EOF?
  79.         jnz    AtEOF
  80.         mov    al, Buffer        ;Get the character read and
  81.         puth                ; print it in hex
  82.         mov    al, ' '         ;Print a space between values
  83.         putc
  84.         jmp    ReadFileLp
  85.  
  86. BadRead:        print
  87.         byte    cr, lf
  88.         byte    'Error reading data from file, aborting.'
  89.         byte    cr,lf,0
  90.  
  91. AtEOF:        mov    bx, FileHandle        ;Close the file
  92.         mov    ah, 3Eh
  93.         int    21h
  94.  
  95. ;---------------------------------------------------------------
  96.  
  97. PgmExit:    ExitPgm
  98. MainPgm     endp
  99.  
  100. TestDelimiter    proc    near
  101.         cmp    al, ' '
  102.         je    xit
  103.         cmp    al, ','
  104.         je    xit
  105.         cmp    al, Tab
  106.         je    xit
  107.         cmp    al, ';'
  108.         je    xit
  109.         cmp    al, '='
  110. xit:        ret
  111. TestDelimiter    endp
  112. cseg        ends
  113.  
  114. dseg        segment    byte public 'data'
  115.  
  116. PSP        word    ?
  117. Filename    byte    64 dup (0)        ;Filename to dump
  118. FileHandle    word    ?
  119. Buffer        byte    ?
  120. Position        word    0
  121.  
  122. dseg        ends
  123.  
  124. sseg        segment    byte stack 'stack'
  125. stk        word    0ffh dup (?)
  126. sseg        ends
  127.  
  128. zzzzzzseg    segment    para public 'zzzzzz'
  129. LastBytes    byte    16 dup (?)
  130. zzzzzzseg    ends
  131.         end    MainPgm
  132.